[WIP] Fix race condition in refresh token issuance#478
[WIP] Fix race condition in refresh token issuance#478pavinduLakshan wants to merge 3 commits intomainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/browser/src/__legacy__/helpers/authentication-helper.ts`:
- Around line 179-205: The httpRequestAll path still bypasses the deduplication
by calling this._authenticationClient.refreshAccessToken() directly; change
httpRequestAll to call the class method refreshAccessToken() (the one that uses
_refreshAccessTokenPromise) instead of invoking
_authenticationClient.refreshAccessToken() so all refresh requests funnel
through the existing de-dupe logic; update any calls in httpRequestAll that
reference _authenticationClient.refreshAccessToken to use
this.refreshAccessToken(), ensuring the error handling and window.postMessage
behavior remains intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a6ac56a8-7ea4-4efe-8d3a-d8ead6667e9e
📒 Files selected for processing (1)
packages/browser/src/__legacy__/helpers/authentication-helper.ts
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. |
Purpose
This pull request updates the
AuthenticationHelperclass to ensure that only one access token refresh operation can be in progress at a time. It introduces logic to track and reuse an in-flight token refresh promise, preventing duplicate refresh requests and potential race conditions.Concurrency improvements for access token refresh:
_refreshAccessTokenPromiseto track an ongoing access token refresh operation, ensuring that concurrent calls torefreshAccessTokenshare the same promise and do not trigger multiple refreshes.refreshAccessTokenmethod to check for an existing refresh promise and return it if present, otherwise create and store a new one. The promise is cleared after completion or error, ensuring proper cleanup. [1] [2]Related Issues
Related PRs
Checklist
Security checks
Summary by CodeRabbit
Release Notes